/**
 * 
 * @test 继承  伪类
 * @author  wsq
 * @data 2020-4-10
 * 
 */

//给函数增加 method 方法
Function.prototype.method= function (name,func){
    // 增加之前先判断是否已经存在
    if(!this.prototype[name]){
        this.prototype[name]=func;
    }
    return this;
}
//构造函数
var Mammal = function (name) {
    this.name = name;
};
Mammal.prototype.says = function() {
    return this.saying ||'';
};

// 构建伪类
// 定义inherits 方法
Function.method('inherits',function(Parent){
    this.prototype = new Parent();
    return this;
});
// 级联调用
// inherits和method都返回this
var Cat = function (name){
    this.name = name;
    this.saying = '喵喵';
}.
    inherits(Mammal) .
    method ('purr', function (n){
    var i, s ='';
    for (i =0; i <n; i += 1){
    if (s){
    s +='-';
    }
    s +='r';
  }
    return s;
}).
    method ('get_name', function(){
    return this.says()+' ' +this . name +
    ''+this.says() ;
    });
    
// 构建实例
var myCat=new Cat('miaomiao');
console.log(myCat.says());  //喵喵
